import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class VIN {
    private String vin;
    private String result;
    private Map DICT_VIS_DATE = new HashMap<String,String>();
    public VIN(String vin){
        this.vin = vin;
        String ffid = "";
        String vmi = "";
        String year = "";
        DICT_VIS_DATE.put("K", "1989");
        DICT_VIS_DATE.put("L", "1990");
        DICT_VIS_DATE.put("M", "1991");
        DICT_VIS_DATE.put("N", "1992");
        DICT_VIS_DATE.put("P", "1993");
        DICT_VIS_DATE.put("R", "1994");
        DICT_VIS_DATE.put("S", "1995");
        DICT_VIS_DATE.put("T", "1996");
        DICT_VIS_DATE.put("V", "1997");
        DICT_VIS_DATE.put("W", "1998");
        DICT_VIS_DATE.put("X", "1999");
        DICT_VIS_DATE.put("Y", "2000");
        DICT_VIS_DATE.put("1", "2001");
        DICT_VIS_DATE.put("2", "2002");
        DICT_VIS_DATE.put("3", "2003");
        DICT_VIS_DATE.put("4", "2004");
        DICT_VIS_DATE.put("5", "2005");
        DICT_VIS_DATE.put("6", "2006");
        DICT_VIS_DATE.put("7", "2007");
        DICT_VIS_DATE.put("8", "2008");
        DICT_VIS_DATE.put("9", "2009");
        DICT_VIS_DATE.put("A", "2010");
        DICT_VIS_DATE.put("B", "2011");
        DICT_VIS_DATE.put("C", "2012");
        DICT_VIS_DATE.put("D", "2013");
        DICT_VIS_DATE.put("E", "2014");
        DICT_VIS_DATE.put("F", "2015");
        DICT_VIS_DATE.put("G", "2016");
        DICT_VIS_DATE.put("H", "2017");
        DICT_VIS_DATE.put("J", "2018");





        if (vin == "" || vin == null) {
            result = "vin为空:vin为空:vin为空";
        } else if(vin.length()==17){
            vin = vin.toUpperCase();
            Pattern pattern = Pattern.compile("(L[0-9ABCDEFGHJKLMNPRSTUVWXYZ]{16})");
            Matcher matcher = pattern.matcher(vin);
            if (matcher.find()) {
                ffid = matcher.group(1);
                vmi = ffid.substring(0, 8);
                year=ffid.substring(9,10);
                if(DICT_VIS_DATE.containsKey(year)){
                    result = vin + ":"+vmi +":"+DICT_VIS_DATE.get(year);
                }else {
                    result = "vin码错误:vin码错误:vin码错误";
                }



            } else {
                result = "国外车:国外车:国外车";
            }

        } else {
            result = "vin码错误:vin码错误:vin码错误";

        }


    }

    public String getResult() {
        return result;
    }
}

